/**
  ******************************************************************************
  * @file    gt32f030_awk.c
  * @author  GT Application Team
  * @version V1.0.0
  * @date    03-January-2025       
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 Giantec Semicondutor Inc</center></h2>
  *
  *             http://www.giantec-semi.com/
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/ 
#include "gt32f030_rcc.h"
#include "gt32f030_awk.h"

/** @addtogroup GT32F030_StdPeriph_Driver
  * @{
  */
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/

#define AWK_SR_WAKEUP   ((uint32_t)0x00000001)
#define AWK_CR_ENABLE   ((uint32_t)0x00000010)

/** @defgroup AWK 
  * @brief AWK driver modules
  * @{
  */ 

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup AWK_Private_Functions
  * @{
  */ 

/** @defgroup AWK_Init Initialization functions
 *  @brief   Initialization and functions
@verbatim    
 ===============================================================================
              ##### Initialization functions #####
 ===============================================================================
@endverbatim
  * @{
  */
	
/**
  * @brief  Deinitializes the AWK peripheral registers to their default reset values.
  * @param  None
  * @retval None
  */
void AWK_DeInit(void)
{
  RCC_PeriphResetCmd(RCC_PeriphReset_AWK,ENABLE);
	RCC_PeriphResetCmd(RCC_PeriphReset_AWK,DISABLE);
}

/**
  * @brief  Initializes the AWK peripheral according to the specified
  *         parameters in the AWK_InitStruct .
  * @param  AWK_InitStruct: pointer to a AWK_InitTypeDef structure that contains
  *         the configuration information.
  * @retval None
  */
void AWK_Init(AWK_InitTypeDef* AWK_InitStruct)
{
	/* Check the parameters */
  assert_param(IS_AWK_CLKSRC(AWK_InitStruct->AWK_ClkSource)); 
  assert_param(IS_AWK_CLKPRESCALEDIV(AWK_InitStruct->AWK_CLKPreScaleDiv));
	assert_param(IS_AWK_HXTPRESCAL(AWK_InitStruct->AWK_HXTPreScale));
	assert_param(IS_AWK_RELOAD(AWK_InitStruct->AWK_Reload));
	
  /*---------------------------- AWK CON & RLDVAL Configuration -----------------*/
  AWK->CR    = (AWK_InitStruct->AWK_HXTPreScale<<8) | \
	             (AWK_InitStruct->AWK_CLKPreScaleDiv);
	
	AWK->RLOAD = AWK_InitStruct->AWK_Reload; 
}

/**
  * @brief  Fills each AWK_InitStruct member with its default value.
  * @param  AWK_InitStruct: pointer to a AWK_InitTypeDef structure
  *         which will be initialized.
  * @retval None
  */
void AWK_StructInit(AWK_InitTypeDef* AWK_InitStruct)
{
	AWK_InitStruct->AWK_CLKPreScaleDiv  = AWK_CLKPreScale_Div2;
	AWK_InitStruct->AWK_HXTPreScale     = 0xBC;
	AWK_InitStruct->AWK_Reload          = 0x00;
}
/**
  * @}  
  */

/** @defgroup AWK_OpCfg Operation and Configuration functions
 *  @brief   Operation and Configuration functions
 *
@verbatim   
 ===============================================================================
           ##### Operation and Configuration functions #####
 ===============================================================================  
@endverbatim
  * @{
  */

/**
  * @brief  Enables or disables the AWK .
  * @param  NewState: new state of the AWK.
  *         This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void AWK_Cmd(FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_FUNCTIONAL_STATE(AWK_InitStruct->AWK_Cmd));
	
	if (NewState != DISABLE)
  {
    AWK->CR |= AWK_CR_ENABLE;
  }
  else
  {
    AWK->CR &= ~AWK_CR_ENABLE;
  }
}

/**
  * @brief  Set the AWK Reload value.
  * @param  Reload: the AWK Reload value.
  * @retval None
  */
void AWK_SetReloadVal(uint8_t Reload)
{
	/* Check the parameters */
  assert_param(IS_AWK_RELOAD(Reload));
  AWK->RLOAD = Reload;
}
/**
  * @}  
  */


/** @defgroup  AWK_IntrFlag Interrupts and flags management functions
 *  @brief    Interrupts and flags management functions
 *
@verbatim   
 ===============================================================================
           #####  Interrupts and flags management functions #####
 ===============================================================================  
@endverbatim
  * @{
  */
/**
  * @brief  Checks whether the AWK interrupt flag is set or not.
  * @param  None
  * @retval The new state of AWK (SET or RESET).
  */
ITStatus AWK_GetIT(void)
{
  ITStatus bitstatus = RESET;
  if (AWK->SR&AWK_SR_WAKEUP)
  {
    bitstatus = SET;
  }
  else
  {
    bitstatus = RESET;
  }
  return  bitstatus;
}

/**
  * @brief  Clears the AWK interrupt flags.
  * @param  None
  * @retval None.
  */
void AWK_ClearIT(void)
{
  AWK->INTCLR = 0x1;
}

/**
  * @}  
  */ 

/**
  * @}  
  */

/**
  * @}  
  */ 

/**
  * @}
  */ 
/************************ (C) COPYRIGHT Giantec Semicondutor Inc *****END OF FILE****/
